package net.maku.custom.biza.controller.reveiveable;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import lombok.AllArgsConstructor;
import net.maku.custom.biza.controller.reveiveable.query.ReceivablesQuery;
import net.maku.custom.biza.controller.reveiveable.vo.ReceivablesVO;
import net.maku.custom.biza.service.reveiveable.ReceivablesService;
import net.maku.framework.common.page.PageResult;
import net.maku.framework.common.utils.Result;
import org.springframework.web.bind.annotation.*;

/**
* 应收款
*
* @author NULL
* @since 1.0.0 2022-07-12
*/
@RestController
@RequestMapping("/receivables")
@Tag(name="应收款")
@AllArgsConstructor
public class ReceivablesController {
    private final ReceivablesService receivablesService;

    @GetMapping("/page")
    @Operation(summary = "分页")
    public Result<PageResult<ReceivablesVO>> page(@Valid ReceivablesQuery query){
        PageResult<ReceivablesVO> page = receivablesService.page(query);

        return Result.ok(page);
    }

    @GetMapping("/{id}")
    @Operation(summary = "信息")
    public Result<ReceivablesVO> get(@PathVariable("id") Long id){
        ReceivablesVO receivablesVO = receivablesService.selectById(id);

        return Result.ok(receivablesVO);
    }

    @PostMapping("/save")
    @Operation(summary = "保存")
    public Result<String> save(@RequestBody ReceivablesVO vo){
        receivablesService.save(vo);

        return Result.ok();
    }

    @PostMapping("/update")
    @Operation(summary = "修改")
    public Result<String> update(@RequestBody @Valid ReceivablesVO vo){
        receivablesService.update(vo);

        return Result.ok();
    }

    @PostMapping("/delete")
    @Operation(summary = "删除")
    public Result<String> delete(@RequestBody List<Long> idList){
        receivablesService.delete(idList);

        return Result.ok();
    }

    @PostMapping("/downloadInvoice")
    @Operation(summary = "下载发票")
    public void downloadInvoice(HttpServletResponse response,@RequestBody List<Long> idList) {
        receivablesService.downloadInvoice(response,idList);
    }
}